package com.example.loginvoice_android;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class ParametersActivity extends AbsLoginActivity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.parameters_layout);

		final TextView txt = (TextView) findViewById(R.id.textView1);
		txt.setText("Please enter the IP adress of the server.");
		
		final EditText ed1 = (EditText) findViewById(R.id.editText1);
		
		final Button button = (Button) findViewById(R.id.button1);
		button.setText("Save parameters");
        button.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
            	// Save in a file the IP entered
            	String ip = "";
            	ip = ed1.getText().toString();
            	System.out.println("IP : "+ip);
            	
            	FileOutputStream fOut = null; 
                OutputStreamWriter osw = null; 
         
                try{ 
                    fOut = getBaseContext().openFileOutput("settings.dat", MODE_PRIVATE);       
                    osw = new OutputStreamWriter(fOut); 
                    osw.write(ip); 
                    osw.flush(); 
                   //popup
                    Toast.makeText(getBaseContext(), "Settings saved",Toast.LENGTH_SHORT).show(); 
                    } 
                    catch (Exception e) {       
                            Toast.makeText(getBaseContext(), "Settings not saved",Toast.LENGTH_SHORT).show(); 
                    } 
                    finally { 
                       try { 
                              osw.close(); 
                              fOut.close(); 
                              } catch (IOException e) { 
                                       Toast.makeText(getBaseContext(), "Settings not saved",Toast.LENGTH_SHORT).show(); 
                              } 
                    } 
                ed1.setText("");
            }
        });
	}
}
